@section('content')
<div class="am-g m-user">
	<div class="am-u-md-12">
		<div class="m-user-title am-cf">
			<h1>我的账户</h1>
			<!-- 
			<span class="free-tip">订单满500元免运费</span>
			 -->
		</div>
	</div>
	<div class="am-u-md-12">
		<div class="m-user-hd">
			<ul class="am-cf">
				<li><a href="{{URL::to('user/order-list')}}">我的订单</a></li>
				<li><a href="{{URL::to('user/address-list')}}">地址</a></li>
				<li><a href="{{URL::to('user/info')}}">登陆资料</a></li>
				<li><a href="{{URL::to('user/favorite-list')}}">收藏夹</a></li>
			</ul>
		</div>
		<div class="m-user-bd">
			<ul>
				<li>
					<h3>登陆资料</h3>
					<span>查看或修改您的登陆资料</span>
				</li>
			</ul>
			
			<div class="m-login am-cf">
				<div class="m-login-bd">
					<div class="m-register">
						<form class="am-form"  id="update-userinfo-form" name="update-userinfo-form" method="post" 
								action="{{URL::to('user/update')}}">
							<div class="am-form-group">
						      <label for="name">姓名<span class="m-required">*</span></label>
							  <div class="am-cf m-horizontal-group">
						      <input type="text" class="m-input validate" id="name" name="name" 
								data-rules="required|max_length[32]" data-display="姓名" placeholder="输入姓名" value="{{$user->name}}">
							  <span class="m-field-error"></span>
				              </div>
						    </div>
							<div class="am-form-group">
						      <label for="mobile">手机<span class="m-required">* 非常重要，如有问题便于我们与您联系</span></label>
						      <div class="am-cf m-horizontal-group">
							 <input type="text" class="m-input validate" id="mobile" name="mobile" readonly="readonly"
								data-rules="required|max_length[16]|mobile" data-display="手机号" placeholder="输入手机号" value="{{$user->mobile}}">
							  <span class="m-field-error"></span>
							</div>
						    </div>
						    <div class="am-form-group">
						      <label for="email">邮箱<span class="m-required">*</span></label>
							 <div class="am-cf m-horizontal-group">
						      <input type="text" class="m-input validate" id="email" name="email"  readonly="readonly"
								data-rules="required|max_length[128]|valid_email" data-display="电子邮箱" placeholder="输入电子邮箱" value="{{$user->email}}">
				              <span class="m-field-error"></span>
					          </div>
						    </div>
							{{Form::token()}}
							
						    <p><button type="submit" class="m-btn" data-am-loading="{spinner: 'circle-o-notch', loadingText: '保存中...', resetText: '保存成功',errorText:'保存失败'}">保存</button></p>
						    <p class="m-form-error"></p>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
    </div>
</div>

@stop
@section('script')
<script type="text/javascript">
  $(function(){
	  var $form = $("#update-userinfo-form");
	  var $submit = $form.find('button');
	  var errorFn = function(errors){
			$form.find(".m-field-error").html("");
			if ($.isArray(errors)){
				  $.each(errors,function(i,e){
					  var $msg = $(e.element).next();
					  $msg.text(e.message);
				  });
			  } else {
				  for (var key in errors){
					  var $ele = $form.find("#"+key).next();
					  $ele.text(errors[key][0]);
				  }
			}
		}
	  $form.validate(function($form,errors,events){
			errorFn(errors);
	  });
	  var options = {
	            beforeSubmit:function(){
	            	$submit.button('loading');
	            },
	            success: function (data) {
		            if (!data.success){
		            	errorFn(data.errors);
		            	$submit.button('error');
			        } else {
			        	$submit.button('reset');
					}
	            }
	   };
	   $form .ajaxForm(options);
  });

</script>
@stop
